package com.ruoyi.service.impl;

import com.ruoyi.domain.ZhwyAdvancedeposit;
import com.ruoyi.domain.ZhwyChargeitem;
import com.ruoyi.domain.ZhwyPaymentmethod;
import com.ruoyi.mapper.ZhwyAdvancedepositMapper;
import com.ruoyi.mapper.ZhwyChargeitemMapper;
import com.ruoyi.mapper.ZhwyPaymentmethodMapper;
import com.ruoyi.service.IZhwyAdvancedepositService;
import com.ruoyi.system.domain.ZhwyShops;
import com.ruoyi.system.mapper.ZhwyShopsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 预存款信息表Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-07
 */
@Service
public class ZhwyAdvancedepositServiceImpl implements IZhwyAdvancedepositService {
    @Autowired
    private ZhwyAdvancedepositMapper zhwyAdvancedepositMapper;
    @Autowired
    private ZhwyShopsMapper zhwyShopsMapper;
    @Autowired
    private ZhwyChargeitemMapper zhwyChargeitemMapper;
    @Autowired
    private ZhwyPaymentmethodMapper zhwyPaymentmethodMapper;

    /**
     * 查询预存款信息表
     *
     * @param id 预存款信息表主键
     * @return 预存款信息表
     */
    @Override
    public ZhwyAdvancedeposit selectZhwyAdvancedepositById(Long id) {
        return zhwyAdvancedepositMapper.selectZhwyAdvancedepositById(id);
    }

    /**
     * 查询预存款信息表列表
     *
     * @param zhwyAdvancedeposit 预存款信息表
     * @return 预存款信息表
     */
    @Override
    public List<ZhwyAdvancedeposit> selectZhwyAdvancedepositList(ZhwyAdvancedeposit zhwyAdvancedeposit) {
        if (zhwyAdvancedeposit.getShopsCode()!=null){
            ZhwyShops zhwyShops1=new ZhwyShops();
            zhwyShops1.setCode(zhwyAdvancedeposit.getShopsCode());
            List<ZhwyShops> zhwyShopsList = zhwyShopsMapper.selectZhwyShopsList(zhwyShops1);
            ZhwyShops zhwyShops2 = zhwyShopsList.get(0);

            zhwyAdvancedeposit.setShopsId(zhwyShops2.getId());
        }
        List<ZhwyAdvancedeposit> list = zhwyAdvancedepositMapper.selectZhwyAdvancedepositList(zhwyAdvancedeposit);
        for (ZhwyAdvancedeposit zad : list) {
            ZhwyShops zhwyShops = zhwyShopsMapper.selectZhwyShopsById(zad.getShopsId());

            ZhwyChargeitem zhwyChargeitem = zhwyChargeitemMapper.selectZhwyChargeitemById(zad.getChargeItemId());

            ZhwyPaymentmethod zhwyPaymentmethod = zhwyPaymentmethodMapper.selectZhwyPaymentmethodById(zad.getPayId());
            zad.setShopsCode(zhwyShops.getCode());
            if (zhwyChargeitem != null) {
                zad.setChargeItemName(zhwyChargeitem.getName());
            }

            if (zhwyPaymentmethod != null) {
                zad.setPaymentMethodName(zhwyPaymentmethod.getName());
            }

        }
        return list;
    }

    /**
     * 新增预存款信息表
     *
     * @param zhwyAdvancedeposit 预存款信息表
     * @return 结果
     */
    @Override
    public int insertZhwyAdvancedeposit(ZhwyAdvancedeposit zhwyAdvancedeposit) {
        UUID uuid = UUID.randomUUID();
        System.out.println(uuid);
        zhwyAdvancedeposit.setPayNo("PAY"+uuid.toString());
        return zhwyAdvancedepositMapper.insertZhwyAdvancedeposit(zhwyAdvancedeposit);
    }

    /**
     * 修改预存款信息表
     *
     * @param zhwyAdvancedeposit 预存款信息表
     * @return 结果
     */
    @Override
    public int updateZhwyAdvancedeposit(ZhwyAdvancedeposit zhwyAdvancedeposit) {
        return zhwyAdvancedepositMapper.updateZhwyAdvancedeposit(zhwyAdvancedeposit);
    }

    /**
     * 批量删除预存款信息表
     *
     * @param ids 需要删除的预存款信息表主键
     * @return 结果
     */
    @Override
    public int deleteZhwyAdvancedepositByIds(Long[] ids) {
        return zhwyAdvancedepositMapper.deleteZhwyAdvancedepositByIds(ids);
    }

    /**
     * 删除预存款信息表信息
     *
     * @param id 预存款信息表主键
     * @return 结果
     */
    @Override
    public int deleteZhwyAdvancedepositById(Long id) {
        return zhwyAdvancedepositMapper.deleteZhwyAdvancedepositById(id);
    }
}
